diff --git a/web/pgadmin/browser/server_groups/servers/__init__.py b/web/pgadmin/browser/server_groups/servers/__init__.py index b2cca09..89ae779 100644 --- a/web/pgadmin/browser/server_groups/servers/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/__init__.py @@ -886,9 +886,12 @@ class ServerNode(PGChildNodeView): if server is None: return bad_request(gettext("Server not found.")) - # Fetch User Details. - user = User.query.filter_by(id=current_user.id).first() - if user is None: + if current_user and hasattr(current_user, 'id'): + # Fetch User Details. + user = User.query.filter_by(id=current_user.id).first() + if user is None: + return unauthorized(gettext("Unauthorized request.")) + else: return unauthorized(gettext("Unauthorized request.")) data = request.form if request.form else json.loads( diff --git a/web/pgadmin/browser/server_groups/servers/databases/templates/databases/css/database.css b/web/pgadmin/browser/server_groups/servers/databases/templates/databases/css/database.css index 5300189..f0b12e3 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/templates/databases/css/database.css +++ b/web/pgadmin/browser/server_groups/servers/databases/templates/databases/css/database.css @@ -9,6 +9,6 @@ .icon-database-not-connected { background-image: url('{{ url_for('NODE-database.static', filename='img/databasebad.svg') }}') !important; - border-radius: 10px + border-radius: 10px; background-size: 20px !important; } diff --git a/web/pgadmin/static/css/bootstrap.overrides.css b/web/pgadmin/static/css/bootstrap.overrides.css index b0c531a..d2936a7 100755 --- a/web/pgadmin/static/css/bootstrap.overrides.css +++ b/web/pgadmin/static/css/bootstrap.overrides.css @@ -1438,3 +1438,9 @@ body { .multi-checkbox .check.partial:after { content: "\003F"; } + +/* Override default bootstrap popover fonts & size */ +.popover-content { + font-family: 'Open Sans'; + font-size: 13px; +} diff --git a/web/pgadmin/static/js/sqleditor_utils.js b/web/pgadmin/static/js/sqleditor_utils.js index ea775a5..5ef0d17 100644 --- a/web/pgadmin/static/js/sqleditor_utils.js +++ b/web/pgadmin/static/js/sqleditor_utils.js @@ -8,8 +8,8 @@ ////////////////////////////////////////////////////////////////////////// // This file contains common utilities functions used in sqleditor modules -define(['jquery'], - function ($) { +define(['jquery', 'sources/gettext'], + function ($, gettext) { var sqlEditorUtils = { /* Reference link http://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript * Modified as per requirement. @@ -55,6 +55,125 @@ define(['jquery'], }, capitalizeFirstLetter: function (string) { return string.charAt(0).toUpperCase() + string.slice(1); + }, + // Status flag + previousStatus: null, + // This function will fetch the connection status via ajax + fetchConnectionStatus: function(url, $el, $status_el) { + $.ajax({ + url: url, + method: 'GET', + success: function (res) { + if(res && res.data) { + var status = res.data.status, + msg = res.data.message, + is_status_changed = false; + + // Inject CSS as required + switch(status) { + // Busy + case 1: + // if received busy status more than once then only + if(status == sqlEditorUtils.previousStatus && + !$status_el.hasClass('fa-hourglass-half')) { + $status_el.removeClass() + .addClass('fa fa-hourglass-half'); + is_status_changed = true; + } + break; + // Idle in transaction + case 2: + if(sqlEditorUtils.previousStatus != status && + !$status_el.hasClass('fa-clock-o')) { + $status_el.removeClass() + .addClass('fa fa-clock-o'); + is_status_changed = true; + } + break; + // Failed in transaction + case 3: + if(sqlEditorUtils.previousStatus != status && + !$status_el.hasClass('fa-exclamation-circle')) { + $status_el.removeClass() + .addClass('fa fa-exclamation-circle'); + is_status_changed = true; + } + break; + // Failed in transaction with unknown server side error + case 4: + if(sqlEditorUtils.previousStatus != status && + !$status_el.hasClass('fa-exclamation-triangle')) { + $status_el.removeClass() + .addClass('fa fa-exclamation-triangle'); + is_status_changed = true; + } + break; + default: + if(sqlEditorUtils.previousStatus != status && + !$status_el.hasClass('fa-query_tool_connected')) { + $status_el.removeClass() + .addClass('fa-custom fa-query-tool-connected'); + is_status_changed = true; + } + } + + sqlEditorUtils.previousStatus = status; + // Set bootstrap popover message + if(is_status_changed) { + $el.popover('hide'); + $el.attr('data-content', msg); + } + } else { + // We come here means we did not receive expected response + // from server, we need to error out + sqlEditorUtils.previousStatus = -99; + msg = gettext("Something went wrong, " + + "make sure you are logged into pgAdmin4."); + $el.attr('data-content', msg); + if(!$status_el.hasClass('fa-query-tool-disconnected')) { + $el.popover('hide'); + $status_el.removeClass() + .addClass('fa-custom fa-query-tool-disconnected'); + } + } + }, + error: function (e) { + sqlEditorUtils.previousStatus = -1; + var msg = gettext("Transaction status check failed."); + if (e.readyState == 0) { + msg = gettext("Not connected to the server or the connection to " + + "the server has been closed."); + } else if (e.responseJSON && e.responseJSON.errormsg) { + msg = e.responseJSON.errormsg; + } + + // Set bootstrap popover + $el.attr('data-content', msg); + // Add error class + if(!$status_el.hasClass('fa-query-tool-disconnected')) { + $el.popover('hide'); + $status_el.removeClass() + .addClass('fa-custom fa-query-tool-disconnected'); + } + } + }); + }, + // This function will update the connection status + updateConnectionStatus: function(url, poll_time) { + var $el = $(".connection_status"), + $status_el = $($($el).find(".fa-custom")); + + // Apply popover on element + $el.popover(); + + // To set initial connection status + sqlEditorUtils.fetchConnectionStatus(url, $el, $status_el); + + // Calling it again in specified interval + setInterval( + sqlEditorUtils.fetchConnectionStatus.bind(null, url, $el, $status_el), + poll_time * 1000 + ); } }; return sqlEditorUtils; diff --git a/web/pgadmin/tools/datagrid/__init__.py b/web/pgadmin/tools/datagrid/__init__.py index 726a0ff..1c9dadc 100644 --- a/web/pgadmin/tools/datagrid/__init__.py +++ b/web/pgadmin/tools/datagrid/__init__.py @@ -149,10 +149,11 @@ def initialize_datagrid(cmd_type, obj_type, sid, did, obj_id): else: sql_grid_data = session['gridData'] - # Use pickle to store the command object which will be used - # later by the sql grid module. + # Use pickle to store the command object which will be used later by the + # sql grid module. sql_grid_data[trans_id] = { - 'command_obj': pickle.dumps(command_obj, -1) # -1 specify the highest protocol version available + # -1 specify the highest protocol version available + 'command_obj': pickle.dumps(command_obj, -1) } # Store the grid dictionary into the session variable @@ -195,15 +196,20 @@ def panel(trans_id, is_query_tool, editor_title): user_agent = UserAgent(request.headers.get('User-Agent')) """ - Animations and transitions are not automatically GPU accelerated and by default use browser's slow rendering engine. - We need to set 'translate3d' value of '-webkit-transform' property in order to use GPU. - After applying this property under linux, Webkit calculates wrong position of the elements so panel contents are not visible. - To make it work, we need to explicitly set '-webkit-transform' property to 'none' for .ajs-notifier, .ajs-message, .ajs-modal classes. - - This issue is only with linux runtime application and observed in Query tool and debugger. - When we open 'Open File' dialog then whole Query-tool panel content is not visible though it contains HTML element in back end. - - The port number should have already been set by the runtime if we're running in desktop mode. + Animations and transitions are not automatically GPU accelerated and by + default use browser's slow rendering engine. We need to set 'translate3d' + value of '-webkit-transform' property in order to use GPU. After applying + this property under linux, Webkit calculates wrong position of the elements + so panel contents are not visible. To make it work, we need to explicitly + set '-webkit-transform' property to 'none' for .ajs-notifier, + .ajs-message, .ajs-modal classes. + + This issue is only with linux runtime application and observed in Query + tool and debugger. When we open 'Open File' dialog then whole Query tool + panel content is not visible though it contains HTML element in back end. + + The port number should have already been set by the runtime if we're + running in desktop mode. """ is_linux_platform = False @@ -218,15 +224,20 @@ def panel(trans_id, is_query_tool, editor_title): new_browser_tab = 'false' if is_query_tool == 'true': - prompt_save_changes = pref.preference('prompt_save_query_changes').get() + prompt_save_changes = pref.preference( + 'prompt_save_query_changes' + ).get() else: prompt_save_changes = pref.preference('prompt_save_data_changes').get() + display_connection_status = pref.preference( + 'display_connection_status' + ).get() + # Fetch the server details - # bgcolor = None fgcolor = None - if str(trans_id) in session['gridData']: + if 'gridData' in session and str(trans_id) in session['gridData']: # Fetch the object for the specified transaction id. # Use pickle.loads function to get the command object session_obj = session['gridData'][str(trans_id)] @@ -240,9 +251,12 @@ def panel(trans_id, is_query_tool, editor_title): fgcolor = s.fgcolor or 'black' return render_template( - "datagrid/index.html", _=gettext, uniqueId=trans_id, + "datagrid/index.html", + _=gettext, + uniqueId=trans_id, is_query_tool=is_query_tool, - editor_title=editor_title, script_type_url=sURL, + editor_title=editor_title, + script_type_url=sURL, is_desktop_mode=app.PGADMIN_RUNTIME, is_linux=is_linux_platform, is_new_browser_tab=new_browser_tab, @@ -252,7 +266,8 @@ def panel(trans_id, is_query_tool, editor_title): fgcolor=fgcolor, # convert python boolean value to equivalent js boolean literal before # passing it to html template. - prompt_save_changes='true' if prompt_save_changes else 'false' + prompt_save_changes='true' if prompt_save_changes else 'false', + display_connection_status=display_connection_status ) diff --git a/web/pgadmin/tools/datagrid/templates/datagrid/index.html b/web/pgadmin/tools/datagrid/templates/datagrid/index.html index ff4368d..02bbd4f 100644 --- a/web/pgadmin/tools/datagrid/templates/datagrid/index.html +++ b/web/pgadmin/tools/datagrid/templates/datagrid/index.html @@ -1,8 +1,5 @@ {% extends "base.html" %} {% block title %}{{ config.APP_NAME }} - Datagrid{% endblock %} -{% block css_link %} - -{% endblock %} {% block body %}
@@ -284,7 +289,25 @@
-
+ +
+ {% if display_connection_status %} +
+
+ +
+
+ {% endif %} +
+
+